import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get.dart';
import 'package:note/common/common.dart';
import 'package:note/manager/global.dart';
import 'package:note/widgets/noteCard.dart';

import 'logic.dart';

class NoteListPage extends StatelessWidget {
  NoteListPage({Key? key}) : super(key: key);

  final logic = Get.put(NoteListPageLogic());
  final state = Get.find<NoteListPageLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      if (GlobalUtil.noteList.isEmpty) {
        return Center(
            child: Text(
          Strings.noNote,
          style: Styles.textTransparentMedium(30),
        ));
      }
      return Scrollbar(
        controller: state.scrollController,
        radius: const Radius.circular(15),
        thickness: 10,
        interactive: true,
        child: SlidableAutoCloseBehavior(
          child: ListView(
            padding: EdgeInsets.zero,
            controller: state.scrollController,
            children: [
              ...List.generate(GlobalUtil.noteList.length,
                  (index) => NoteCard(GlobalUtil.noteList[index])),
            ],
          ),
        ),
      );
    });
  }
}
